#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>

int main()
{
	pid_t pid;
	pid = fork();
	if(pid == 0)
	{
		sleep(5);
		exit(5);
	}
	printf("child pid : %d\n",pid);
	int ret = 0;
	int status = 0;
	while(ret == 0)
	{
		ret = waitpid(pid,&status,WNOHANG);
		printf("Child is running!\n");
		sleep(1);
	}
	if(ret > 0 && WIFEXITED(status))
	{
		printf("wait success! ret : %d, exit code : %d\n",ret,(status>>8)&0xFF);
	}
	else if(ret > 0)
	{
		printf("sig code:%d\n",status&0x7F);
	}
	return 0;
}


